package com.assess.web.controller;

import com.assess.web.model.Scheme;
import com.assess.web.service.SchemeService;
import com.assess.web.util.RespParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/scheme")
public class SchemeController extends BaseController {
    @Autowired
    private SchemeService schemeService;

    /**
     * 获取方案
     *
     * @param parentId
     * @return
     */
    @ResponseBody
    @RequestMapping("list")
    public RespParam<List<Scheme>> listScheme(@RequestParam(name = "parentId", required = false) Integer parentId) {
        return success(schemeService.listScheme(parentId));
    }

    /**
     * 创建个（方案抽取范围）
     *
     * @param parentId
     * @param name
     * @return
     */
    @ResponseBody
    @RequestMapping("save")
    public RespParam<Integer> save(@RequestParam(name = "parentId", required = false) Integer parentId,
                                   @RequestParam(name = "name") String name) {
        return success(schemeService.save(parentId, name.trim()));

    }

    /**
     * 删除方案抽取范围
     *
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping("delete")
    public RespParam<Boolean> delete(@RequestParam("id") Integer id) {
        schemeService.delete(id);
        return success(true);
    }
}
